Imports System.Text
Imports System.Web

Public Class SUM_Schema
    Private Const Q As String = Chr(34)
    Private mlDatabaseID As Long
    Private msBaseURL As String = ""

    Private mbDataExists As Boolean = False

    Public Sub New( _
                ByVal sBaseURL As String, _
                ByVal lDatabaseID As Long)

        msBaseURL = sBaseURL
        mlDatabaseID = lDatabaseID
    End Sub

    Public ReadOnly Property DataExists() As Boolean
        Get
            Return mbDataExists
        End Get
    End Property

    Public Function Summerize() As String
        Dim oQueueFactory As New SQLAutoDocLib.ScanQueue_Factory

        Dim oDatabase As New SQLAutoDocLib.Database(mlDatabaseID)
        oDatabase.Load()

        Dim oSum As New StringBuilder

        With oSum
            .Append("<span style=" & Q & "font-size: 12px; font-weight: bold;" & Q & ">")
            .Append("Database Schema Changes, last 10 days")
            .Append("<br/>")
            .Append("</span>")

            .Append("<span style=" & Q & "font-size: 10px; font-weight: normal;" & Q & ">")
            .Append("Last scan: " & oQueueFactory.GetLastQueuedRequest(mlDatabaseID, SQLAutoDocLib.ScanSchedule.Type.SchemaScan))
            .Append("<br/>")
            .Append("</span>")

            Dim oStatusReport As New SQLAutoDocLib.RPT_Status

            .Append("<span style=" & Q & "font-size: 12px; font-weight: bold;" & Q & ">")
            .Append(oStatusReport.SchemaChanges( _
                                        oDatabase.ServerID, _
                                        mlDatabaseID, _
                                        msBaseURL, _
                                        DateAdd(DateInterval.Day, -7, Now), _
                                        DateAdd(DateInterval.Day, 1, Now)))

            .Append("</span>")

            mbDataExists = oStatusReport.DataExists
        End With

        Return oSum.ToString
    End Function
End Class
